package com.x.erp.manage;

import com.x.erp.dao.MultilevelActivityAccountDao;
import com.x.erp.model.MultilevelActivityAccount;
import com.x.erp.model.MultilevelActivityCash;
import com.x.framework.manage.BaseManage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class MultilevelActivityCashManage extends BaseManage{

	@Autowired
	private MultilevelActivityAccountDao multilevelActivityAccountDao;// 多级营销账户管理

	public MultilevelActivityCash insertMultilevelActivityShare(MultilevelActivityCash multilevelActivityCash) throws Exception {
		MultilevelActivityAccount multilevelActivityAccount = new MultilevelActivityAccount();
		multilevelActivityAccount.setUserId(multilevelActivityCash.getUserId());
		List<MultilevelActivityAccount> list = multilevelActivityAccountDao.selectMultilevelActivityAccountList(multilevelActivityAccount);
		if (list != null && list.size() > 0){
			multilevelActivityAccountDao.updateAddBalance(multilevelActivityAccount.getUserId(), new BigDecimal(0));
			multilevelActivityCash.setCashMoney(list.get(0).getAccountBalance());
			MultilevelActivityCash multilevelActivityCashInfo = this.insert(multilevelActivityCash);
			return multilevelActivityCashInfo;
		}
		return null;
	}
}
